﻿using System;
using System.Diagnostics;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace OutlookPhotoAddIn
{
    public partial class ThisAddIn
    {
        #region Instance Variables

        private Outlook.Application _Application;
        internal static Office.IRibbonUI _Ribbon;

        #endregion

        #region Properties

        public stdole.IPictureDisp Pictdisp
        {
            get
            {
                // Get IPictureDisp for CurrentUser in realtime
                try
                {
                    Outlook.AddressEntry addrEntry =
                        Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
                    if (addrEntry.Type == "EX")
                    {
                        Outlook.ExchangeUser exchUser =
                            addrEntry.GetExchangeUser() as Outlook.ExchangeUser;
                        return exchUser.GetPicture() as stdole.IPictureDisp;
                    }
                    return null;
                }
                catch (Exception ex)
                {
                    //Write exception to debug window
                    Debug.WriteLine(ex.Message);
                    return null;
                }
            }
        }

        #endregion

        #region VSTO Startup and Shutdown methods

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Initialize variables
            _Application = this.Application;
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            // Shutdown code here
            _Ribbon = null;
            _Application = null;
        }

        protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            return new OutlookPhotoAddin(_Application);
        }

        #endregion

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}
